﻿using MDIDemo.Model;
using MDIDemo.PublicClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevMy.Vou
{
    public partial class Form_ProjectBase : Form_BaseDialog
    {
        public Form_ProjectBase()
        {
            InitializeComponent();
        }
        public ProjectMainModel projectMainModel;
        public void Ini()
        {
            base.SetComponent();
        }
        /// <summary>
        /// 窗体状态
        /// </summary>
        /// <param name="WinType">-1：查看，0：修改，1：增加</param>
        public void SetWinType(int WinType)
        {
            base.WinType = WinType;
        }

        protected override void DisplayComponent(string id)
        {
            base.class_ComboBoxEdit.SetComboBoxEdit(this.comboBoxEdit1, null);
            base.class_ComboBoxEdit.SetComboBoxEdit(this.comboBoxEdit2
            , base.class_SQLiteOperator.GetAllDictionary("AAC").ToArray());
            //base.class_SetTextEdit.SetTextEdit(this.textEdit1, false, Color.Black);
            //base.class_SetTextEdit.SetTextEdit(this.textEdit2, false, Color.Black);
            base.class_SetMemoEdit.SetMemoEdit(this.memoEdit1, false);

            #region 加入用户列表
            string SelectSql = "SELECT nickName";
            string FormSql = "FROM sys_useinfo";
            string WhereSql = null;
            string GroupSql = null;
            string HavingSql = null;
            string OrderSql = "ORDER BY nickName";
            string UseSql = base.class_MySqlDataBase.GetAll(SelectSql
                , FormSql
                , WhereSql
                , GroupSql
                , HavingSql
                , OrderSql);
            DataTable dataTableUse = base.class_MySqlDataBase.GetDataTable(UseSql);
            if (dataTableUse != null)
            {
                for (int i = 0; i < dataTableUse.Rows.Count; i++)
                {
                    this.comboBoxEdit1.Properties.Items.Add(dataTableUse.Rows[i]["nickName"]);
                }
            }
            dataTableUse.Dispose();
            #endregion

            if (id != null)
            {
                string Sql = string.Format(@"Select main.id
                    , main.projectName
                    , main.projectAddress
                    , main.projectManager
                    , main.projectType
                    , main.remark
                    , main.createDate
                    From vou_project As main
                    WHERE main.id = '{0}'
                    Order by createDate DESC"
                    , id);
                DataTable dataTable = base.class_MySqlDataBase.GetDataTable(Sql);
                if (dataTable != null && dataTable.Rows.Count == 1)
                {
                    DataRow dataRow = dataTable.Rows[0];
                    if (dataRow != null)
                    {
                        this.textEdit1.Text = dataRow["projectName"].ToString();
                        this.textEdit2.Text = dataRow["projectAddress"].ToString();
                        this.comboBoxEdit1.Text = dataRow["projectManager"].ToString();
                        this.comboBoxEdit2.Text = dataRow["projectType"].ToString();
                        this.memoEdit1.Text = dataRow["remark"].ToString();
                    }
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if (this.textEdit1.Text == "" || this.textEdit1.Text.Length == 0)
            {
                MessageBox.Show("项目名称不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.comboBoxEdit1.SelectedIndex < 0)
            {
                MessageBox.Show("项目负责人不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.comboBoxEdit2.SelectedIndex < 0)
            {
                MessageBox.Show("测试类型不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            projectMainModel = new ProjectMainModel();
            if (WinType == 1)
                projectMainModel.id = Class_Tool.GenerateId();
            else
                projectMainModel.id = base.id;
            projectMainModel.projectName = this.textEdit1.Text;
            projectMainModel.projectAddress = this.textEdit2.Text;
            projectMainModel.projectManager = this.comboBoxEdit1.Text;
            projectMainModel.projectType = this.comboBoxEdit2.Text;
            projectMainModel.remark = this.memoEdit1.Text;
            this.DialogResult = DialogResult.OK;
        }
    }
}
